// poj3764
// 题意：给定一个树，求树上最大路径异或值。
//
// 题解：求出每个点到根的异或值，然后转化成给定一列数，
//       求出两个数的异或最大。这只需要建立字典树，然后在字典树上贪心走就好。
//       每次再把当前查询完的数插入字典树。
//
// 统计：476ms, 1h 5min, 3wa
//
// run: $exec < input
#include <cstdio>
#include <algorithm>
#include <cstring>

int const maxn = 100007;
int const max_len = 33;

struct trie
{
	trie * child[2];
	int count;
} trie_node[maxn * max_len], * trie_head = trie_node;

int trie_alloc = 1;

int bit[max_len];

int head[maxn], next[2 * maxn], end_point[2 * maxn], cost[2 * maxn];
int alloc = 1;
int to_root[maxn];
int n;

void add_edge(int u, int v, int c)
{
	end_point[alloc] = v; cost[alloc] = c; next[alloc] = head[u]; head[u] = alloc++;
	end_point[alloc] = u; cost[alloc] = c; next[alloc] = head[v]; head[v] = alloc++;
}

void path_to_root(int u, int f, int d)
{
	to_root[u] = d;
	for (int p = head[u]; p; p = next[p]) {
		int v = end_point[p], c = cost[p];
		if (v == f) continue;
		path_to_root(v, u, d ^ c);
	}
}

void convert(int x)
{
	std::memset(bit, 0, sizeof(bit));
	for (int i = max_len - 1; x && i; i--, x /= 2)
		bit[i] = x & 1;
}

int query()
{
	trie * p = trie_head;
	if (!p->child[0] && !p->child[1]) return 0;
	int ret = 0;
	for (int i = 0; i < max_len; i++) {
		int cur = bit[i];
		if (bit[i] == 1) {
			if (p->child[0])
				p = p->child[0];
			else {
				p = p->child[1];
				cur = 0;
			}
		} else {
			if (p->child[1]) {
				p = p->child[1];
				cur = 1;
			} else p = p->child[0];
		}
		ret = ret * 2 + cur;
	}
	return ret;
}

trie * trie_node_alloc()
{
	trie_node[trie_alloc].child[0] = trie_node[trie_alloc].child[1] = NULL;
	trie_node[trie_alloc].count = 0;
	return trie_node + trie_alloc++;
}

void trie_insert()
{
	trie * p = trie_head;
	for (int i = 0; i < max_len; i++) {
		int tmp = bit[i];
		if (!p->child[tmp]) p->child[tmp] = trie_node_alloc();
		else p->child[tmp]->count++;
		p = p->child[tmp];
	}
}

void init()
{
	std::memset(head, 0, sizeof(head));
	alloc = trie_alloc = 1;
	trie_head->child[0] = NULL;
	trie_head->child[1] = NULL;
}

int main()
{
	while (std::scanf("%d", &n) != EOF) {
		init();

		for (int i = 1, x, y, z; i < n; i++) {
			std::scanf("%d %d %d", &x, &y, &z);
			add_edge(x, y, z);
		}

		path_to_root(0, -1, 0);

		int ans = 0;
		for (int i = 0; i < n; i++) {
			convert(to_root[i]);
			ans = std::max(ans, to_root[i]);
			ans = std::max(ans, query());
			trie_insert();
		}
		std::printf("%d\n", ans);
	}
}

